package com.wd.tw.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wd.common.core.domain.HttpResponse;
import com.wd.tw.domain.dto.EleRunDataQuery;
import com.wd.tw.domain.vo.EChartsLineData;
import com.wd.tw.domain.vo.EChartsPieData;
import com.wd.tw.domain.vo.EleRunTotal;
import com.wd.tw.service.ElevatorReportService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.wd.tw.constants.EleConstant.*;

/**
 * @className: ReportController
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2025/1/10
 **/
@RestController
public class ReportController {


    @Resource
    ElevatorReportService elevatorReportService;


    @GetMapping("/report/eleRun/total")
    public HttpResponse getEleRunTotal(EleRunDataQuery query) {
        List<EleRunTotal> eleRunTotalList = elevatorReportService.getEleRunTotal(query);
        HttpResponse httpResponse = HttpResponse.successData(eleRunTotalList);
        httpResponse.setCode(0);
        return httpResponse;
    }

    @GetMapping("/report/eleRun/data")
    public HttpResponse getEleRunData(EleRunDataQuery query) {
        EChartsLineData runData = elevatorReportService.getRunData(query);
        HttpResponse httpResponse = HttpResponse.successData(runData);
        httpResponse.setCode(0);
        return httpResponse;
    }

    @GetMapping("/report/eleRun/times")
    public HttpResponse getEleRunTimes(EleRunDataQuery query) {
        EChartsLineData runData = elevatorReportService.getRunTimes(query);
        HttpResponse httpResponse = HttpResponse.successData(runData);
        httpResponse.setCode(0);
        return httpResponse;
    }

    @GetMapping("/report/eleRun/pCount")
    public HttpResponse getElePersonCount(EleRunDataQuery query) {
        List<EChartsPieData> personCount = elevatorReportService.getPersonCount(query);
        HttpResponse httpResponse = HttpResponse.successData(personCount);
        httpResponse.setCode(0);
        return httpResponse;
    }


    @GetMapping("/current/reset")
    public HttpResponse resetPerson(@RequestParam Long cameraId) {
        Map<String, Integer> map = ELE_PERSON_ORIGIN_OFFSET.get(cameraId);
        if(map!=null)
        {
            Integer inCount = map.get("InCount");
            Integer outCount = map.get("OutCount");

            ELE_PERSON_COUNT_OFFSET.put(cameraId,inCount-outCount);
        }
        HttpResponse response = HttpResponse.success();
        response.setCode(0);
        return response;
    }

    @GetMapping("/current/person")
    public HttpResponse getCurrentPerson() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("抓拍", ELE_PERSON_COUNT);
        jsonObject.put("越界", ELE_PERSON_COUNT_BOUNDARY);
        HttpResponse httpResponse = HttpResponse.successData(jsonObject);
        httpResponse.setCode(0);
        return httpResponse;
    }
}
